package cn.wolfcode.wolf2w.job;

import cn.wolfcode.wolf2w.redis.service.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.redis.service.IUserInfoRedisService;
import cn.wolfcode.wolf2w.redis.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.ITravelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * redis数据持久化
 */

@Component
public class RedisDataPersistenceJob {

    @Autowired
    private IStrategyStatisVORedisService strategyStatisVORedisService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;

    @Scheduled(cron = "0 0 1 * * ?") // 定时任务标签 1小时
    //@Scheduled(cron = "0/5 * * * * ?") // 定时任务标签 5秒
    public void doWork() {
        System.out.println("----------------攻略vo对象 redis 持久化 start----------");

        // 从redis中获取所有vo对象
        List<StrategyStatisVO> vos = strategyStatisVORedisService.queryStartegyVos(false);
        // 遍历vo对象 执行攻略对象更新
        for (StrategyStatisVO vo : vos) {
            strategyService.updateStatisVo(vo);
        }

        System.out.println("----------------攻略vo对象 redis 持久化 end----------");

        System.out.println("----------------游记vo对象 redis 持久化 start----------");

        // 从redis中获取所有vo对象
        List<StrategyStatisVO> tvos = strategyStatisVORedisService.queryStartegyVos(true);
        // 遍历vo对象 执行游记对象更新
        for (StrategyStatisVO vo : tvos) {
            travelService.updateStatisVo(vo);
        }

        System.out.println("----------------游记vo对象 redis 持久化 end----------");
    }

}